{
LANG : PASCAL
PROB : gift1
}

program GIFT1;
const
  fi = 'gift1.in';
  fo = 'gift1.out';
  max = 10;
var
  name : array[1..max] of string;
  money : array[1..max] of longint;
  n : integer;

procedure inp;
var
  i : longint;
begin
  readln(n);
  for i := 1 to n do readln(name[i]);
  fillchar(money, sizeof(money), 0);
end;

function ID(s : string) : integer;
var
  i : integer;
begin
  for i := 1 to n do
    if s = name[i] then
    begin
      ID := i;
      exit;
    end;
end;

procedure process;
var
  i, m, sl, giver, friend : integer;
  s : string;
begin
  while not eof do
  begin
    readln(s);
    giver := ID(s);
    readln(m, sl);
    if sl = 0 then continue;
    dec(money[giver], m);
    inc(money[giver], m mod sl);
    for i := 1 to sl do
    begin
      readln(s);
      friend := ID(s);
      inc(money[friend], m div sl);
    end;
  end;
end;

procedure out;
var
  i : integer;
begin
  for i := 1 to n do writeln(name[i], ' ', money[i]);
end;

begin
  assign(input, fi); reset(input);
  assign(output, fo); rewrite(output);
  inp;
  process;
  out;
  close(output);
  close(input);
end.